<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时不可以修改本文件，影响升级覆盖
 */

class Shouce extends \Phpcmf\Home\Module
{

    public function index() {
        // $this->_module_init();// 
		//get获取id
		$id = (int)\Phpcmf\Service::L('input')->get('id');
        $jianjie = \Phpcmf\Service::M()->db->table('1_shouce')
            ->join('1_shouce_data_0', '1_shouce.id = 1_shouce_data_0.id')
            ->where('1_shouce.id', $id)
            ->get()
            ->getRowArray();
        
		// 导航接口
		$daohang_data = \Phpcmf\Service::M()->table('1_shouce_form_son_daohang')->where('cid',$id)->getAll();
		//->where('yincang', 0)
        //循环导航，导航分别有一级 和 二级 导航
        $daohang = [];
        foreach ($daohang_data as $key => $val) {
            // 一级导航
                if($val['yijiid']==0){
					$daohang[$key]['id'] = $val['id'];
					$daohang[$key]['name'] = $val['name'];
					//一级内容
					$list_1_data = \Phpcmf\Service::M()->table('1_shouce_form_son')->where('tid',$val['id'])->order_by('displayorder asc,id asc')->getAll();
					$daohang[$key]['list'] = $list_1_data;
					
					    // 二级导航
						$daohang_2_data = \Phpcmf\Service::M()->table('1_shouce_form_son_daohang')->where('yijiid',$val['id'])->getAll();
						// 二级导航
						$daohang[$key]['erji'] = [];
						foreach ($daohang_2_data as $key2 => $val2) {
							$daohang[$key]['erji'][$key2]['id'] = $val2['id'];
							$daohang[$key]['erji'][$key2]['name'] = $val2['name'];
							
							//二级内容
							$list_2_data = \Phpcmf\Service::M()->table('1_shouce_form_son')->where('tid',$val2['id'])->order_by('displayorder asc,id asc')->getAll();
							$daohang[$key]['erji'][$key2]['list'] = $list_2_data;
							
						}
					
				}
				
                
            
        }
        // $daohang 输出json数据
        $jianjie['content'] = htmlspecialchars_decode($jianjie['content']);
         // 
         $data = [
            'lisi' => $daohang, 
            'jianjie' => $jianjie,
            
         ];

        $this->_json('1', '读取成功', $data);
        
    }

}
